package eg.backend.query;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import eg.backend.domain.Dimension;

public class AggregateSO {
	private Date from;
	private Date to;
	private String name;

	private String userId;
	private String categoryPosition;
	private String category;
	
	private List<Dimension> dimensions = new ArrayList<Dimension>();
	
	private Map<String, List<String>> constraints = new HashMap<String, List<String>>();
	
	private Dimension viewBy;
	@SuppressWarnings("unused")
	private Integer count;
	private String tag;
	private String shop;

	private List<String> excludedDimensions = new ArrayList<String>();
	
	public AggregateSO() {

	}

	public Date getFrom() {
		return from;
	}

	public void setFrom(Date from) {
		this.from = from;
	}

	public Date getTo() {
		return to;
	}

	public void setTo(Date to) {
		this.to = to;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getCategoryPosition() {
		return categoryPosition;
	}

	public void setCategoryPosition(String categoryPosition) {
		this.categoryPosition = categoryPosition;
	}

	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public String getShop() {
		return shop;
	}

	public void setShop(String shop) {
		this.shop = shop;
	}

	//root dimension shouldn't be considered as a constraint
	public List<Dimension> getDimensions() {
		List<Dimension> effectiveDimensions = new ArrayList<Dimension>();
		for(Dimension dimension : dimensions) {
			if(dimension.getParent() != null) {
				effectiveDimensions.add(dimension);
			}
		}
		return effectiveDimensions;
	}

	public void setDimensions(List<Dimension> dimensions) {
		this.dimensions = dimensions;
	}

	public void addDimension(Dimension dimension) {
		this.dimensions.add(dimension);
	}

	public Dimension getViewBy() {
		return viewBy;
	}

	public void setViewBy(Dimension viewBy) {
		this.viewBy = viewBy;
	}
	
	public void addDimensionIds(String dimension, List<String> dimensionIds) {
		this.constraints.put(dimension, dimensionIds);
	}
	
	public void setDimensionIds(Map<String, List<String>> dimensionIds) {
		constraints = new HashMap<String, List<String>>();
		Set<String> keySet = dimensionIds.keySet();
		for(String key : keySet) {
			this.constraints.put(key, dimensionIds.get(key));
		}
	}

	public Map<String, List<String>> getConstraints() {
		return constraints;
	}

	public String getTag() {
		return tag;
	}

	public void setTag(String tag) {
		this.tag = tag;
	}

	public List<String> getExcludedDimensions() {
		return excludedDimensions;
	}

	public void setExcludedDimensions(List<String> excludedDimensions) {
		this.excludedDimensions = excludedDimensions;
	}
	
	public boolean excludes(long id) {
		return excludes("" + id);
	}
	
	public boolean excludes(String id) {
		return this.excludedDimensions.contains(id);
	}
	
}
